package com.bangbang.blog.service.impl;

import com.bangbang.blog.pojo.TbCourse;
import com.bangbang.blog.mapper.TbCourseMapper;
import com.bangbang.blog.service.ITbCourseService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程商品表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-08-11
 */
@Service
public class TbCourseServiceImpl extends ServiceImpl<TbCourseMapper, TbCourse> implements ITbCourseService {

    @Autowired
    private TbCourseMapper tbCourseMapper;

    @Override
    public List<TbCourse> selectByMap(String couName,String couTeacherId,int couHour, int couWhetherLiveStreaming) {
        QueryWrapper<TbCourse> wrapper = new QueryWrapper<>();
        Map<String,Object> map = new HashMap<>();
        if(!StringUtils.isBlank(couName)){
            wrapper.like("cou_name",couName);
        }

        if(couTeacherId != null){
            wrapper.eq("cou_teacher_id",couHour);
        }
        if(couHour>0){
            wrapper.eq("cou_hour",couHour);
        }
        if(couWhetherLiveStreaming>=0){
            wrapper.eq("cou_whether_live_streaming",couWhetherLiveStreaming);
        }

        List<TbCourse> TbCourse = tbCourseMapper.selectList(wrapper);
        return TbCourse;
    }

    @Override
    public void deleteById(Integer courseId) {
        tbCourseMapper.deleteById(courseId);
    }

    @Override
    public void insertCourse(TbCourse course) {
        tbCourseMapper.insert(course);
    }
}
